package br.com.dao;

import java.sql.SQLException;
import org.hibernate.Session;
import br.com.model.Usuario;
import br.com.util.BancoUtil;

/**
 * @author ramonsv89
 *
 */

public class UsuarioDAO {
	
	public boolean autenticar(Usuario user) throws SQLException{
		
		String query = "select u from Usuario as u where u.login=:login and u.senha=:senha";
	
		Session session = BancoUtil.getFactory().openSession();
		session.beginTransaction();
		
		Usuario usuario = (Usuario) session.createQuery(query).setString("login", user.getLogin()).setString("senha", user.getSenha()).uniqueResult();
		session.getTransaction().commit();
		session.close();
		return usuario != null;
	}

}
